<?php
/**
 * Created by JetBrains PhpStorm.
 * User: joedarkangel3
 * Date: 8/25/11
 * Time: 7:06 PM
 * To change this template use File | Settings | File Templates.
 */
$this->load->view('intro'); ?>
<body id="food_item">
<?php $this->load->view('admin/navigation'); ?>
<div id="edit_section">
<div id="message_block" style="width:600px;""><?php echo $message; ?></div>
    <form id="main_form" method="post" action="index.php/admin/food_item/add">
        <input type="hidden" name="target_id" id="target_id" value="" />
        <label for="item_en_input">item: </label>
        <input maxlength="64" type="text" name="en_name" id="item_en_input" value="" />
        <label for="item_ch_input">item(ch): </label>
        <input maxlength="64" type="text" name="ch_name" id="item_ch_input" value="" />
        <label for="row_select_lable">Row: </label>
  <select name="row_select" id="row_select">
    <option value="1">1</option>
    <option value="2">2</option>
    <option value="3">3</option>
    <option value="4">4</option>
    <option value="5">5</option>
    <option value="6">6</option>
  </select>
  <label for="column_select_lable">Column: </label>
  <select name="col_select" id="col_select">
    <option value="1">1</option>
    <option value="2">2</option>
    <option value="3">3</option>
    <option value="4">4</option>
    <option value="5">5</option>
  </select>
        <label>Size</label><label>En Name</label><label>Ch Name</label><label>Price</label><br/>
        <label>Size 1: </label>
        <input maxlength="5" type="text" name="size1en_name" id="size1_en_input" value="" />
        <input maxlength="5" type="text" name="size1ch_name" id="size1_ch_input" value="" />
        <input type="text" class="double_field" name="size1price" id="size1_price_input" value="" /><br/>
        <label>Size 2: </label>
        <input maxlength="5" type="text" name="size2en_name" id="size2_en_input" value="" />
        <input maxlength="5" type="text" name="size2ch_name" id="size2_ch_input" value="" />
        <input type="text" class="double_field" name="size2price" id="size2_price_input" value="" /><br/>
        <label>Size 3: </label>
        <input maxlength="5" type="text" name="size3en_name" id="size3_en_input" value="" />
        <input maxlength="5" type="text" name="size3ch_name" id="size3_ch_input" value="" />
        <input type="text" class="double_field"  name="size3price" id="size3_price_input" value="" /><br/>
        <div id="edit_food_item_button">
            <label>Category: </label>
            <select name="category_id" id="category_group" onkeyup="change_category()" onchange="change_category()">
            <?php foreach($food_category as $category): ?>
            <option
            <?php if($cat_select == $category['id']) echo "selected=\"selected\""; ?>
            value="<?=$category['id']?>"><?=$category['en_name']?></option>
            <?php endforeach; ?>
            </select><br /><br /><br />

        <label for="is_spicy_checkbox">*Spicy: </label>
        <input name="is_spicy" id="is_spicy_checkbox" type="checkbox" />
            <input id="add_form_button" type="submit" style="display:inline-block; height:40px; width:90px;" value="add food" />
            <input id="update_form_button" type="submit" style="display:inline-block; height:40px; width:90px;" value="update food" />
        </div>
    </form>
    <!-- helper form to redirect -->
    <form action="http://www.vunlin.com/vun/index.php/admin/food_item" method="post" id="helper_form">
        <input id="helper_input" type="hidden" name="cat_select" value="" />
    </form>
    <br /><hr style="border:1px solid #ccc;"/>
    
    <?php
    $sequence_opt = "";
    for($i=1; $i<7; $i++) {
        for($j=1; $j<6; $j++) {
            $sequence = $i . "-" . $j;
            if(array_key_exists($sequence, $foods)){
                $food = $foods[$sequence];
            ?>
                <?php $sequence_opt .= "<option value=\"" . $food['id'] . "_" . $sequence . "\">" . $sequence . "</option>"; ?>
                <div id="<?php echo $food['id']; ?>" style="font-size:20px;" class="button"><?php echo $food['en_name']; ?></div>
            <?php
            }
            else{
            ?>
                <div id="none" style="visibility:hidden;" class="button">empty</div>
            <?php
            }
        }
    }
    ?>
<form action="index.php/admin/food_item/swap" method="post">
  <select name="swap_from" id="swap_from"><?php echo $sequence_opt; ?></select>
  <select name="swap_to" id="swap_to"><?php echo $sequence_opt; ?></select>
  <input style="display:block; width:140px; height:50px;" type="submit" value="swap category">
</form>
<div style="position: relative; top:-80px; left:240px;">
<form action="index.php/admin/food_item/delete" method="post">
  <select name="delete_sequence" id="delete_from"><?php echo $sequence_opt; ?></select>
  <input disable="disable" style="display:block; width:140px; height:50px;" type="submit" value="delete category">
</form>
</div>
</div>

<script type="text/javascript">
function change_category(){
    var $cat_select = $("#category_group").val();
    $("#helper_input").val($cat_select);
    $("#helper_form").submit();
}

$(document).ready(function(){
    $(".button").click(function(){
      var $id = $(this).attr("id");
      var $data = {target_id:  $id};
      $.ajax({
        type: "POST",
        url: "index.php/admin/food_item/read",
        dataType: "json",
        data: $data,
        success: function(msg){
          var $en_name = msg.en_name;
          var $ch_name = msg.ch_name;
          var $row = msg.sequence[0];
          var $col = msg.sequence[2];
          $("#target_id").val(msg.id);
          $("#item_en_input").val($en_name);
          $("#item_ch_input").val($ch_name);
          $("#row_select").val($row);
          $("#col_select").val($col);
          $("#main_form").attr("action", "index.php/admin/food_item/update");
          $("#add_form_button").attr("disabled", "disabled");
          if(msg.is_spicy == 1){
            $("#is_spicy_checkbox").prop("checked", true);
          }
          else{
            $("#is_spicy_checkbox").prop("checked", false);
          }

          $("#size1_en_input").val(msg.size1en_name);
          $("#size1_ch_input").val(msg.size1ch_name);
          $("#size1_price_input").val(msg.size1price);
          $("#size2_en_input").val(msg.size2en_name);
          $("#size2_ch_input").val(msg.size2ch_name);
          $("#size2_price_input").val(msg.size2price);
          $("#size3_en_input").val(msg.size3en_name);
          $("#size3_ch_input").val(msg.size3ch_name);
          $("#size3_price_input").val(msg.size3price);
        }
      });
    });
  });

</script>
<?php $this->load->view('outro'); ?>
